package com.kexio.file.storage;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 存储文件信息
 * 
 * 封装存储后端返回的文件信息
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public class StorageFileInfo {
    
    /**
     * 文件大小
     */
    private Long fileSize;
    
    /**
     * 内容类型
     */
    private String contentType;
    
    /**
     * 最后修改时间
     */
    private LocalDateTime lastModified;
    
    /**
     * ETag（如果支持）
     */
    private String etag;
    
    /**
     * 文件哈希值
     */
    private String fileHash;
    
    /**
     * 存储类别（如果支持）
     */
    private String storageClass;
    
    /**
     * 元数据
     */
    private Map<String, String> metadata;
    
    /**
     * 是否存在
     */
    private boolean exists;
    
    // ==================== 构造方法 ====================
    
    public StorageFileInfo() {
    }
    
    public StorageFileInfo(boolean exists) {
        this.exists = exists;
    }
    
    // ==================== 便捷方法 ====================
    
    /**
     * 获取文件大小的人类可读格式
     */
    public String getHumanReadableSize() {
        if (fileSize == null || fileSize <= 0) {
            return "0 B";
        }
        
        String[] units = {"B", "KB", "MB", "GB", "TB"};
        int unitIndex = 0;
        double size = fileSize.doubleValue();
        
        while (size >= 1024 && unitIndex < units.length - 1) {
            size /= 1024;
            unitIndex++;
        }
        
        return String.format("%.1f %s", size, units[unitIndex]);
    }
    
    // ==================== Getter/Setter ====================
    
    public Long getFileSize() {
        return fileSize;
    }
    
    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }
    
    public String getContentType() {
        return contentType;
    }
    
    public void setContentType(String contentType) {
        this.contentType = contentType;
    }
    
    public LocalDateTime getLastModified() {
        return lastModified;
    }
    
    public void setLastModified(LocalDateTime lastModified) {
        this.lastModified = lastModified;
    }
    
    public String getEtag() {
        return etag;
    }
    
    public void setEtag(String etag) {
        this.etag = etag;
    }
    
    public String getFileHash() {
        return fileHash;
    }
    
    public void setFileHash(String fileHash) {
        this.fileHash = fileHash;
    }
    
    public String getStorageClass() {
        return storageClass;
    }
    
    public void setStorageClass(String storageClass) {
        this.storageClass = storageClass;
    }
    
    public Map<String, String> getMetadata() {
        return metadata;
    }
    
    public void setMetadata(Map<String, String> metadata) {
        this.metadata = metadata;
    }
    
    public boolean isExists() {
        return exists;
    }
    
    public void setExists(boolean exists) {
        this.exists = exists;
    }
    
    @Override
    public String toString() {
        return "StorageFileInfo{" +
                "fileSize=" + fileSize +
                ", contentType='" + contentType + '\'' +
                ", lastModified=" + lastModified +
                ", etag='" + etag + '\'' +
                ", fileHash='" + fileHash + '\'' +
                ", storageClass='" + storageClass + '\'' +
                ", exists=" + exists +
                '}';
    }
}
